package game.metalmax.ui.login
{
	
	import flash.display.Bitmap;
	import flash.events.KeyboardEvent;
	import flash.utils.getDefinitionByName;
	
	import game.metalmax.config.GameConfig;
	import game.metalmax.module.server.ServerProxy;
	
	import showtime.framework.manager.AssetManager;
	import showtime.framework.manager.StyleManager;
	import showtime.framework.manager.WindowManager;
	import showtime.framework.music.Music;
	import showtime.framework.motion.eaze;
	import showtime.framework.mvc.patterns.facade.Facade;
	import showtime.framework.ui.Label;
	import showtime.framework.ui.Window;

	public class LoginWindow extends Window
	{
		private var music:Music = new Music();
		
		public function LoginWindow()
		{
			
		}
		
		override protected function initialize():void
		{
			super.initialize();
			
			graphics.beginFill(0x000000);
			graphics.drawRect(0, 0, GameConfig.SCREEN_WIDTH, GameConfig.SCREEN_HEIGHT);
			graphics.endFill();			
		}

		private function keyDownHandler(evt:KeyboardEvent):void
		{
			stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

			ServerProxy(Facade.getInstance().retrieveProxy(String(ServerProxy))).loginC2S("showtime1985@gmail.com", "123456");
			WindowManager.dispose(LoginWindow);			
		}
		
		override public function open():void
		{
			super.open();	
			
			
			music.loadClass(Class(getDefinitionByName("com.metalmax.music.themes.LoginTheme")));
			//music.play();
			
			var backgroundBG:Bitmap = new Bitmap(AssetManager.getInstance().getGraphic("LOGIN_BMP_WELCOME_BG"));
			backgroundBG.alpha = 0;
			backgroundBG.x = 78;
			backgroundBG.y = 43;
			addChild(backgroundBG);
			
			var tileBMP:Bitmap = new Bitmap(AssetManager.getInstance().getGraphic("LOGIN_BMP_WELCOME_TITLE"));
			tileBMP.x = (GameConfig.SCREEN_WIDTH - tileBMP.width) * 0.5;
			tileBMP.y = (GameConfig.SCREEN_HEIGHT - tileBMP.height) * 0.5;
			tileBMP.alpha = 0;			
			addChild(tileBMP);
			
			var informationLab:Label = new showtime.framework.ui.Label(this);
			informationLab.textField.defaultTextFormat = (StyleManager.getInstance().getStyleAsTextFormat("FONT_SYSTEM"));
			informationLab.text = "       PUSH START\n\n©  1996  DATA  EAST \n©  1996  CREA-TECH\n©  2012  SHOW TIME";		
			informationLab.updateDisplayList();
			informationLab.x = (GameConfig.SCREEN_WIDTH - informationLab.textField.textWidth) * 0.5;
			informationLab.y = 300;
			informationLab.alpha = 0;
			
			eaze(tileBMP).to(2, {alpha:1}).to(3, {y:127}).onComplete(function():void{stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);eaze(backgroundBG).to(2, {alpha:1}).onComplete(function():void{eaze(informationLab).to(2, {alpha:1});});});
		}
		
		override public function close():void
		{
			super.close();			
			removeAllChilds();
			music.stop();
			music = null;
		}
		
	
	}
}